<div class="Item hr">
    <span class="fr">系统现有数据模型<b>{$models_count}</b>个</span>
    <div class="current">数据模型列表</div>
</div>
<style type="text/css">
.setStatus:hover{
	color:red;
}
</style>
<form>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tab">
        <thead>
            <tr>
                <td>ID</td>
                <td>模型名</td>
                <td>识别id</td>
                <td>附加表</td>
                <td>状态</td>
                <td>模型</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <volist name="models" id="model" empty="$empty">
            <tr align="center">
                <td>{$model['id']}</td>
                <td>{$model['name']}</td>
                <td>{$model['nid']}</td>
                <td>{$model['addtable']}</td>
                <td>
                <if condition="$model['nid'] neq 'message'">
                <if condition="$model['status'] == 1">
                <a href="javascript:;" class="icon icon-color icon-check setStatus" data-url='{:U("toggleStatus")}' data-id="{$model.id}" data-name="{$model['name']}" data-status='no' title="点击禁用"></a>
                <else/>
                <a href="javascript:;" class="icon icon-color icon-close setStatus" data-url='{:U("toggleStatus")}' data-id="{$model.id}" data-name="{$model['name']}" data-status='yes' title="点击启用"></a>
                </if>
                <else/>
                	<span class="icon icon-darkgray icon-locked"></span>
                </if>
                </td>
                <td><if condition="$model['issystem'] == 1">系统<else/>自动</if></td>
                <td>[ <a href="{:U('Models/show', array('id' => $model['id']))}">查看</a> ] <if condition="$model['issystem'] neq 1">[ <a href="{:U('Models/edit', array('id' => $model['id']))}">编辑</a> ] [ <a href="javascript:void(0);" value="{:U('Models/delete', array('id' => $model['id']))}" name="{$model['name']}({$model['addtable']})" class="del">删除</a> ]</if></td>
            </tr>
            </volist>
        </tbody>
    </table>
</form>

<div class="page">
    {$page}
</div>

<script type="text/javascript">
$(function(){
    $(".del").click(function(){
        var del_link = $(this).attr("value");
        popup.confirm('你真的打算删除 <b>'+ $(this).attr("name")+'</b> 吗?','温馨提示',function(action){
            if(action == 'ok'){
                $.getJSON(del_link, function(json){
                    if (json.status) {
                        popup.success(json.info);
                        setTimeout(function(){
                            popup.close("asyncbox_success");
                        },2000);
                    } else {
                        popup.error(json.info);
                        setTimeout(function(){
                            popup.close("asyncbox_error");
                        },2000);
                    }

                    setTimeout(function(){
                        top.window.location.reload();
                    },1000);
                });
            }
        });

        return false;
    });
	
	
    $(".setStatus").click(function(){
        var url = $(this).data("url");
        var name = $(this).data("name");
        var id = $(this).data("id");
        var status = $(this).data("status");

        popup.confirm("您确定修改？", '温馨提示',function(action){
            if(action == 'ok'){
                $.ajax({
					'url' : url,
					'dataType' : 'JSON',
					'type' : 'POST',
					'data' : {'id' : id, 'status' : status},
					'success' : function(json){
						if (json.status) {
							popup.success(json.info, '设置成功', function(){
								if(json.url){
									window.location.href = json.url;
								}else{
									top.window.location.reload();
								}
							});
							setTimeout(function(){
								popup.close("asyncbox_success");
							},2000);
		
							setTimeout(function(){
								top.window.location.reload();
							},3000);
						} else {
							popup.error(json.info);
							setTimeout(function(){
								popup.close("asyncbox_error");
							},2000);
						}
					}
				});
            }
        });

        return false;
    });
});
</script>
